home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / setup / vbnet / 16 windows forms / subclassingdemo / opacityform.vb < prev    next >
Encoding:
Text File  |  2002-03-16  |  4.5 KB  |  124 lines

  1. Public Class OpacityForm
  2.     Inherits System.Windows.Forms.Form
  3.  
  4. #Region " Windows Form Designer generated code "
  5.  
  6.     Public Sub New()
  7.         MyBase.New()
  8.  
  9.         'This call is required by the Windows Form Designer.
  10.         InitializeComponent()
  11.  
  12.         'Add any initialization after the InitializeComponent() call
  13.  
  14.     End Sub
  15.  
  16.     'Form overrides dispose to clean up the component list.
  17.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  18.         If disposing Then
  19.             If Not (components Is Nothing) Then
  20.                 components.Dispose()
  21.             End If
  22.         End If
  23.         MyBase.Dispose(disposing)
  24.     End Sub
  25.     Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
  26.     Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
  27.     Friend WithEvents TrackBar1 As System.Windows.Forms.TrackBar
  28.     Friend WithEvents Button1 As System.Windows.Forms.Button
  29.  
  30.     'Required by the Windows Form Designer
  31.     Private components As System.ComponentModel.Container
  32.  
  33.     'NOTE: The following procedure is required by the Windows Form Designer
  34.     'It can be modified using the Windows Form Designer.  
  35.     'Do not modify it using the code editor.
  36.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  37.         Me.TrackBar1 = New System.Windows.Forms.TrackBar()
  38.         Me.CheckBox1 = New System.Windows.Forms.CheckBox()
  39.         Me.TextBox1 = New System.Windows.Forms.TextBox()
  40.         Me.Button1 = New System.Windows.Forms.Button()
  41.         CType(Me.TrackBar1, System.ComponentModel.ISupportInitialize).BeginInit()
  42.         Me.SuspendLayout()
  43.         '
  44.         'TrackBar1
  45.         '
  46.         Me.TrackBar1.LargeChange = 10
  47.         Me.TrackBar1.Location = New System.Drawing.Point(40, 160)
  48.         Me.TrackBar1.Maximum = 100
  49.         Me.TrackBar1.Name = "TrackBar1"
  50.         Me.TrackBar1.Size = New System.Drawing.Size(312, 42)
  51.         Me.TrackBar1.TabIndex = 2
  52.         Me.TrackBar1.TickFrequency = 10
  53.         Me.TrackBar1.Value = 100
  54.         '
  55.         'CheckBox1
  56.         '
  57.         Me.CheckBox1.Location = New System.Drawing.Point(256, 32)
  58.         Me.CheckBox1.Name = "CheckBox1"
  59.         Me.CheckBox1.Size = New System.Drawing.Size(144, 16)
  60.         Me.CheckBox1.TabIndex = 1
  61.         Me.CheckBox1.Text = "Make transparent"
  62.         '
  63.         'TextBox1
  64.         '
  65.         Me.TextBox1.Location = New System.Drawing.Point(40, 32)
  66.         Me.TextBox1.Multiline = True
  67.         Me.TextBox1.Name = "TextBox1"
  68.         Me.TextBox1.Size = New System.Drawing.Size(200, 112)
  69.         Me.TextBox1.TabIndex = 0
  70.         Me.TextBox1.Text = "Click on the checkbox to make this textbox transparent."
  71.         '
  72.         'Button1
  73.         '
  74.         Me.Button1.Location = New System.Drawing.Point(256, 80)
  75.         Me.Button1.Name = "Button1"
  76.         Me.Button1.Size = New System.Drawing.Size(120, 48)
  77.         Me.Button1.TabIndex = 3
  78.         Me.Button1.Text = "Fade out and close"
  79.         '
  80.         'OpacityForm
  81.         '
  82.         Me.AutoScaleBaseSize = New System.Drawing.Size(7, 17)
  83.         Me.ClientSize = New System.Drawing.Size(408, 221)
  84.         Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.TrackBar1, Me.CheckBox1, Me.TextBox1})
  85.         Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 11!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  86.         Me.Name = "OpacityForm"
  87.         Me.Text = "OpacityForm"
  88.         CType(Me.TrackBar1, System.ComponentModel.ISupportInitialize).EndInit()
  89.         Me.ResumeLayout(False)
  90.  
  91.     End Sub
  92.  
  93. #End Region
  94.  
  95.     ' change the Opacity property when the user moves the trackbar
  96.  
  97.     Private Sub TrackBar1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.ValueChanged
  98.         Me.Opacity = TrackBar1.Value / 100
  99.     End Sub
  100.  
  101.     ' enforce the transparencykey property
  102.  
  103.     Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
  104.         If CheckBox1.Checked Then
  105.             Me.TransparencyKey = TextBox1.BackColor
  106.         Else
  107.             Me.TransparencyKey = Nothing
  108.         End If
  109.     End Sub
  110.  
  111.     ' fade out the form
  112.  
  113.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  114.         Dim op As Single
  115.  
  116.         For op = Me.Opacity To 0 Step -0.005
  117.             Me.Opacity = op
  118.         Next
  119.  
  120.         MessageBox.Show("Good-bye, folks!")
  121.         Me.Close()
  122.     End Sub
  123. End Class
  124.